const app = getApp()
import util from '../../../utils/util'
import {
  ScoreBankType,
  ServiceList
} from '../../../config/api'

Page({

  /**
   * 页面的初始数据
   */
  data: {
    isEmpty:false,
    topMenus: [], //积分银行顶部菜单数据
    service_list: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.getMenu()
    this.getServiceList()
  },

  getMenu() {
    let that = this;
    let params = {
      type:2,
      pid:0,
      vollege_id: app.globalData.vollege_id
    }
    util.apiRequest(ScoreBankType, params, null).then(r => {
      console.log('积分银行顶部菜单：', r.data.data);
      that.setData({
        topMenus: r.data.data,
      });
    });
  },

  getServiceList() {
    let that = this;
    let params = {
      vollege_id: app.globalData.vollege_id,
      page: 1,
      limit: 100
    }
    util.apiRequest(ServiceList, params, null).then(r => {
      console.log('服务列表', r)
      if (r.data.data.data.length ==0){
        that.setData({
          isEmpty:true
        })
      }
      that.setData({
        service_list: r.data.data.data
      })
    })
  },

  BankToDetail: function(e) {
    let id = e.currentTarget.dataset['index'];
    console.log('点击了积分银行详情', id);
    wx.navigateTo({
      url: '/pages/integralBank/integralDetail/integralDetail?id=' + id + '&title=' + e.currentTarget.dataset['title']
    });
  },

  toDetail: function(e) {
    console.log('eee', e)
    let id = e.currentTarget.dataset.id;
    let status = e.currentTarget.dataset.status;
    if (status == 1 || status == 4) {
      wx.navigateTo({
        url: '/pages/culture/unsolved/unsolved?id=' + id,
      })
    } else {
      wx.navigateTo({
        url: '/pages/culture/resolved/resolved?id=' + id,
      })
    }
  },

  /**
 * 点击跳转到我要上红榜
 */
  ToRed: function () {
    console.log('点击我要上红榜！');
    wx.navigateTo({
      url: "/pages/integralBank/onRedList/onRedList",
    });
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})